
package com.jf.cloud.order.listener;

import cn.hutool.core.collection.CollectionUtil;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.order.service.OrderRefundService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zz
 * @date 2021/1/7
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ORDER_REFUND_CANAL_TOPIC,consumerGroup = RocketMqConstant.ORDER_REFUND_CANAL_TOPIC)
public class OrderRefundCanalConsumer implements RocketMQListener<List<Long>> {

    @Autowired
    private OrderRefundService orderRefundService;

    private static final Logger LOG = LoggerFactory.getLogger(OrderRefundCanalConsumer.class);

    @Override
    public void onMessage(List<Long> refundIds) {
        LOG.info("取消退款订单回调开始... message: " + Json.toJsonString(refundIds));
        if (CollectionUtil.isEmpty(refundIds)) {
            return;
        }
        if (CollectionUtils.isNotEmpty(refundIds)) {
            orderRefundService.cancelWhenTimeOut(refundIds);
        }
    }
}
